package edu.ccut.titan.core;

import java.io.File;
import java.util.Vector;

import org.easymock.EasyMock;
import org.osgi.framework.Bundle;

import junit.framework.TestCase;

public class TitanActivatorTestCase extends TestCase {

	protected Bundle mockBundle = null;

	@Override
	protected void setUp() throws Exception {
		super.setUp();

		this.mockBundle = EasyMock.createMock(Bundle.class);

		EasyMock.expect(
				this.mockBundle.getEntry("META-INF/titan-component.xml"))
				.andReturn(
						TitanActivatorTestCase.class
								.getResource("/META-INF/titan-component.xml"))
				.times(0, 20);

		String[] files = new File(TitanActivatorTestCase.class.getResource("/page")
				.getFile()).list();

		Vector<String> fileVector = new Vector<String>();
		for (String file : files) {
			if (file.equals("test")) {
				fileVector.add("page/" + file + "/");
			} else {
				fileVector.add("page/" + file);
			}
		}

		EasyMock.expect(this.mockBundle.getEntryPaths("page")).andReturn(
				fileVector.elements()).times(0, 20);

		EasyMock.expect(this.mockBundle.getEntry("page/index.jsp")).andReturn(
				TitanActivatorTestCase.class.getResource("/page/index.jsp")).times(
				0, 20);

		EasyMock.expect(this.mockBundle.getEntry("page/.titan")).andReturn(
				TitanActivatorTestCase.class.getResource("/page/.titan")).times(0,
				20);

		files = new File(TitanActivatorTestCase.class.getResource("/page/test")
				.getFile()).list();

		Vector<String> fileTestVector = new Vector<String>();
		for (String file : files) {
			fileVector.add("page/test/" + file);
		}

		EasyMock.expect(this.mockBundle.getEntryPaths("page/test/")).andReturn(
				fileTestVector.elements()).times(0, 20);

		EasyMock.expect(this.mockBundle.getEntry("page/test/test.jsp"))
				.andReturn(
						TitanActivatorTestCase.class
								.getResource("/page/test/test.jsp")).times(0,
						20);

		EasyMock.expect(this.mockBundle.getEntry("logic/.titan")).andReturn(
				TitanActivatorTestCase.class.getResource("/logic/.titan")).times(0,
				20);

		EasyMock.expect(
				this.mockBundle.getEntry("logic/validateUser.logic.xml"))
				.andReturn(
						TitanActivatorTestCase.class
								.getResource("/logic/validateUser.logic.xml"))
				.times(0, 20);

		EasyMock.expect(this.mockBundle.getEntry("action/.titan")).andReturn(
				TitanActivatorTestCase.class.getResource("/action/.titan")).times(
				0, 20);

		EasyMock
				.expect(
						this.mockBundle
								.getEntry("action/validateUser.action.xml"))
				.andReturn(
						TitanActivatorTestCase.class
								.getResource("/action/validateUser.action.xml"))
				.times(0, 20);

		EasyMock.replay(this.mockBundle);
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}
}
